Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
image-promise
Advanced tools
Load one or more images, return a promise. Only 0.4KB, for the browser, no dependencies.
Load one or more images, return a promise. Only 0.4KB, for the browser, no dependencies.
It can be used in two ways:
given a URL, generate an <img>
and wait for it to load:
loadImage('img.jpg').then(/*it's loaded!*/)
given an <img>
, wait for it to load:
const img = document.querySelector('img.my-image');
loadImage(img).then(/*it's loaded!*/)
Pick your favorite:
<script src="dist/image-promise.min.js"></script>
npm install --save image-promise
var loadImage = require('image-promise');
import loadImage from 'image-promise';
loadImage(image)
will return a Promise that resolves when the image load, or fails when the image
var image = 'cat.jpg';
// var image = $('img')[0]; // it can also be an <img> element
loadImage(image)
.then(function (img) {
ctx.drawImage(img, 0, 0, 10, 10);
})
.catch(function () {
console.error('Image failed to load :(');
});
image-promise
can load multiple images at a time
var images = ['cat.jpg', 'dog.jpg'];
// var images = $('img'); // it can also be a jQuery object
// var images = document.querySelectorAll('img'); // or a NodeList
loadImage(images)
.then(function (allImgs) {
console.log(allImgs.length, 'images loaded!', allImgs);
})
.catch(function (err) {
console.error('One or more images have failed to load :(');
console.error(err.errored);
console.info('But these loaded fine:');
console.info(err.loaded);
});
None! But you need to polyfill window.Promise
in IE11 and lower.
MIT © Federico Brigante
FAQs
Load one or more images, return a promise. Only 0.4KB, for the browser, no dependencies.
The npm package image-promise receives a total of 2,139 weekly downloads. As such, image-promise popularity was classified as popular.
We found that image-promise demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.